/******************************************************************************
 * $Id: utils.h,v 1.14 2004/09/22 01:14:28 jimb Exp $
 * @file
 * @author  Jim Brooks http://www.jimbrooks.org
 ******************************************************************************/

#ifndef UTILS_H
#define UTILS_H

#include <regex.h>
extern char tableWhitespace[256];
extern char tableCIdentifier[256];     /* pure C */
extern char tableCishIdentifier[256];  /* C/C++/Java */
extern char tableSymbol[256];

void
InitUtils( void );

FUNC_X
ParseWord( const char*  pc,
           const char** ppWord,
           int          max );

FUNC_X
ParseWordAlphanum( const char*  pc,
                   const char** ppWord,
                   int          max );

const char*
NextLine( const char* pc,
          int         max );

const char*
ToLine( const char*	pc,
        int		line,
        int		maxLineSize );

char*
ToEol( const char* pLine,
       int         max );

gint
LineIdx2LineNum( gchar* pText,
                 gint   idx );

const char*
PastEol( const char* pc );

char*
ExtractLine( const char* pLine,
             int         maxLineLen );

GString*
Segment2GString( char* pInit,
                 int   len );

#ifdef HYPERSRC_SPEED
#define StrLen strlen
#else
size_t
StrLen( const char* pStr );
#endif

#ifdef HYPERSRC_SPEED
#define FindSubstr strstr
#else
char*
FindSubstr( const char* pHaystack,
            const char* pNeedle );
#endif

char*
FindSubstrI( const char* pHaystack,
             const char* pNeedle );

char*
FindSubstrSegment( const char* pHaystack,
                   int         haystackLen,
                   const char* pNeedle,
                   gboolean    caseSens );


char*
FindSubstrReverse( const char* pHaystackTop,
                   const char* pHaystackBottom,
                   const char* pNeedle,
                   P_FUNC_STRCMPX pFuncCmp );

char*
FindRegexSegment( int*        pMatchLen,
                  const char* pHaystack,
                  int         haystackLen,
                  const char* pNeedle,
                  gboolean    caseSens,
                  gboolean    reverse,
                  int         cflags_newline );

char*
FindRegexSegmentFast( int*        pMatchLen,
                      const char* pHaystack, /* -- ASCIIZ string -- */
                      const char* pNeedle ); /* regex pattern */

int
OccurrencesInString( const char* pc,
                     char        c );

int
OccurrencesInSegment( const char* pc1,
                      const char* pc2,
                      char        c );

gboolean
IsStringValid( const char* str, int maxLen );

void
FreeGlistDynamic( GList* pGlist );

void
FreeGlistDynamicFreeElem( gpointer pData,
                          gpointer pUnused );

gint
HashStrcmp( gconstpointer pKey1,
            gconstpointer pKey2 );

guint32
ElfHash( const guchar* pKey,
         guint32       h );

GList*
fast_g_list_append( GList*   list,
                    gpointer data,
                    GList**  last /* IN/OUT */ );

void
ExtractDirFromPathname( const char* pPathname,
                        char**      ppDirBegin, /*OUT*/
                        char**      ppDirEnd    /*OUT*/ );

int
ExtractPathFromPathname( char* pPathname );

char*
ExtractFilenameFromPathname( char* pPathname );

#endif /* UTILS_H */
